﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace studentPortal.Models
{
    public class UserRepository:IAccount
    {
        public user getUserFromPwd(String username, String pwd)
        {
            using(Database1Entities1 cx = new Database1Entities1())
            {
                return cx.users.First(x => x.username.Equals(username) && x.pwd.Equals(pwd));
            }
        }

        public void SaveLogin(user u)
        {
            using (Database1Entities1 cx = new Database1Entities1())
            {
                cx.users.Add(u);
                cx.SaveChanges();
                educationAndexperience ed = new educationAndexperience();
                ed.username = u.username;
                ed.degree = ed.experties = ed.experience = ed.qualification = ed.workPlace = "Not Set";
                
                cx.educationAndexperiences.Add(ed);
                cx.SaveChanges();

            }
        }


        public user getUser(String u)
        {
            using (Database1Entities1 cx = new Database1Entities1())
            {
                return cx.users.First(x => x.username.Equals(u));
            }
        }


        public educationAndexperience getEducation(String s)
        {
            using (Database1Entities1 cx = new Database1Entities1())
            {
                return cx.educationAndexperiences.First(x => x.username.Equals(s));
            }
        }
    }
}